<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>My JSP 'addExpressStyle.jsp' starting page</title>

	</head>

	<body>
	<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">${titlePage}</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		<div class="alert alert-success" id="message" style="display: none">
			<button data-dismiss="alert" class="close">
				×
			</button>
			<span id="content">增加成功</span>

		</div>
		<div class="form-group row">
			<input type="hidden" value="${logisticsCompany.id}"
				id="logisticsCompanys" name="logisticsCompanyId">
				
			<div class="col-sm-4">
				<div class="input-group col-md-12">
					<label for="pmsprinters_corpLevel" class="input-group-text">
						公司:
					</label>
					<input type="text" id="logisticsCompanyName"
						name="logisticsCompanyName"
						value="${logisticsCompany.companyName}"
						class="form-control input-large required" minlength="3" readOnly="true" />
				</div>
			</div>
			
			<div class="col-sm-4">
				<div class="input-group col-md-12">
					<label for="pmsprinters_corpLevel" class="input-group-text">
						客户:
					</label>
					<select name="customers" id="customers" class="form-control">
						<c:forEach items="${customers }" var="obj">
							<option value="${obj.customerCode }">
								${obj.customerName }
							</option>
						</c:forEach>
					</select>
				</div>
			</div>
			
			<c:if test="${areaGroups ne null }">
			<div class="col-sm-4 ">
			  <div class="input-group col-md-12">
				<label for="pmsprinters_corpLevel" class="input-group-text">
					网点:
				</label>
				<select id="areaGroups" name="areaGroups" class="form-control" >
			     <c:forEach items="${areaGroups}" var="obj">
				  <option value="${obj.groupCode}"
					<c:if test="${areaGroupCode eq obj.groupCode}">selected="selected"</c:if>>
					${obj.groupName}
				  </option>
			    </c:forEach>
	    	</select>
	    	</div>
			</div>
			</c:if>
			</div>
			
			<div class="form-group row">
				<div class="col-sm-4">
					<div class="input-group col-md-12">
						<label for="pmsprinters_corpLevel" class="input-group-text">
							名称:
						</label>
							<input type="text" id="expressStyleName" name="styleName"
								class="form-control required" minlength="3" />
							<span id="styleNameMessage"></span>
						
					</div>
				</div>
			
				<div class="col-sm-4">
					<div class="input-group col-md-12">
						<span class="input-group-text">@长度:</span>
						<input class="form-control" id="expressWidth" type="text">
				     </div>
				</div>
				
				<div class="col-sm-4">
					<div class="input-group col-md-12">
						<span class="input-group-text">@宽度:</span>
						<input class="form-control" id="expressHeight" type="text">
				     </div>
				</div>
			</div>
			
            <div class="form-group row">
            	<div class="col-sm-12">
					<textarea rows="20" cols="20" class="form-control" id="styleContent"></textarea>
			  </div>
			</div>
			
			<script type="text/javascript">
		
		function valNumber(tempNumber){
		  var rex_one="^[0-9]+(.[0-9]{0,2})?$";
		  var result_one =tempNumber.match(rex_one);
		  if(result_one==null){
		    return false;
		  }
	   	   return true;
		}
		
	function addAjaxMailExpressStyle() {
		var expressWidth=$("#expressWidth").val();
		var expressHeight=$("#expressHeight").val();
		
		if(!valNumber(expressWidth)){
		   alert("请填入正确的长度");
		   $("#expressWidth").focus();
		   //return;
		}else{
		 expressWidth=expressWidth*100;
		}
		if(!valNumber(expressHeight)){
		   alert("请填入正确的宽度");
		   $("#expressHeight").focus();
		   //return;
		}else{
		   expressHeight=expressHeight*100;
		}
		var expressStyleName = $( "#expressStyleName").val();
        if (expressStyleName == "") {
	         $("#styleNameMessage").html( "<font color=\"red\">请填写模版名称</font>");
	    $(function() {
		setTimeout(function() {
			$("#styleNameMessage")
					.hide();
		}, 6000);
	});
	return;
}
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/addAjaxMailExpressStyle',
			data : {
				areaGroupCode:$("#areaGroups").val(),
				logisticsCompanyId:$("#logisticsCompanys").val(),
				customerCode:$("#customers").val(),
				content:encodeURI($("#styleContent").val()),
				type:'mail',
				expressWidth:expressWidth,
				expressHeight:expressHeight,
				expressStyleName:expressStyleName
			},
			dataType : 'json',
			success : function(data) {
				
				    $("#content").html(data.content);
					$("#message").show();
					$(function() {
						setTimeout(function() {
							$("#message").hide();
						}, 6000);
					});
				
			},
			error : function() {

			}
		});
	}

</script>
			<div class="modal-footer bg-gray">
				<c:if test="${status eq 0 }">
					<input id="button_btn" class="btn btn-primary" type="button" value="增加" onclick="addAjaxMailExpressStyle()"/>
				</c:if>
				<c:if test="${status eq 1 }">
					<input id="button_btn" class="btn btn-primary" type="button" value="更新" onclick="addAjaxMailExpressStyle()"/>
				</c:if>
				<input id="cancel_btn" class="btn" type="button" value="返回" onclick="history.back()" />
			</div>
		</div>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
